package org.xiaojl.dwz;

import java.io.Serializable;

/**
 * 分页参数传递工具类 .
 */
public class PageParam implements Serializable {
    private static final long serialVersionUID = 6297178964005032338L;

    /**
     * 默认为第一页.
     */
    public static final int DEFAULT_PAGE_NUM = 1;

    /**
     * 默认每页记录数(15).
     */
    public static final int DEFAULT_NUM_PER_PAGE = 15;

    /**
     * 最大每页记录数(100).
     */
    public static final int MAX_PAGE_SIZE = 100;

    private int pageNum = DEFAULT_PAGE_NUM; // 当前页数

    private int numPerPage; // 每页记录数
    
    private String orderField; //查询排序的字段
    
    private String orderDirection;//排序方式：升序降序

    /**
     * 默认构造函数
     */
    public PageParam(){}

    /**
     * 带参数的构造函数
     * @param pageNum
     * @param numPerPage
     */
    public PageParam(int pageNum , int numPerPage){
    	this.pageNum = pageNum;
    	this.numPerPage = numPerPage;
    }
    
    /**
     * 带参数的构造函数
     * @param pageNum
     * @param numPerPage
     * @param orderField
     * @param orderDirection
     */
    public PageParam(int pageNum , int numPerPage, String orderField, String orderDirection){
    	this.pageNum = pageNum;
    	this.numPerPage = numPerPage;
    	this.orderField = orderField;
    	this.orderDirection = orderDirection;
    }

    /** 当前页数 */
    public int getPageNum() {
        return pageNum;
    }

    /** 当前页数 */
    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    /** 每页记录数 */
    public int getNumPerPage() {
        return numPerPage > 0 ? numPerPage : DEFAULT_NUM_PER_PAGE;
    }

    /** 每页记录数 */
    public void setNumPerPage(int numPerPage) {
        this.numPerPage = numPerPage;
    }

	public String getOrderField() {
		return orderField;
	}

	public void setOrderField(String orderField) {
		this.orderField = orderField;
	}

	public String getOrderDirection() {
		return "desc".equals(this.orderDirection) ? "desc" : "asc";
	}

	public void setOrderDirection(String orderDirection) {
		this.orderDirection = orderDirection;
	}
}
